package cn.tramy.pinxian.common.util


import java.io.Serializable

/**
 * Created by yanjunhua on 15/5/8.
 */
class Result<T : Any> : Serializable {
    var success: Boolean = true
        private set
    lateinit var status: ResultStatus
        private set
    var pageInfo: CommonPageInfo? = null

    lateinit var data: T
        private set

    private constructor()

    constructor(success: Boolean, code: String, description: String, data: T) {
        this.success = success
        this.status = ResultStatus(code, description)
        this.data = data
    }

    companion object {

        fun <T : Any> OK(data: T? = null): Result<Any> {
            return Result(true, ResultStatus.statusOK, "", data ?: "")
        }

        fun OK(): Result<Any> {
            return OK(null)
        }

        fun FAIL(code: String, description: String): Result<Any> {
            return Result(false, code, description, "")
        }

        fun <T> FAIL(data: T? = null): Result<Any> {
            return Result(false, "", "", data ?: "")
        }

        fun <T> FAIL(code: String, description: String, data: T?): Result<Any> {
            return Result(false, code, description, data ?: "")
        }
    }
}
